-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4390: Sort REPL autocomplete suggestions #4417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test case to dotty.tools.repl.TabcompleteTests
. Something like:
@Test def sortedCompletions =
fromInitialState { implicit state =>
compiler
.compile("class Foo { def comp3 = 3; def comp1 = 1; def comp2 = 2 }")
.stateOrFail
}
.andThen { implicit state =>
val expected = List("comp1", "comp2", "comp3")
assertEquals(expected, tabComplete("(new Foo).comp").suggestions)
}
@@ -219,7 +219,7 @@ object Interactive { | |||
case _ => getScopeCompletions(ctx) | |||
} | |||
interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %") | |||
(completionPos, completions.toList) | |||
(completionPos, completions.toList.sortBy(_.name.show)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use _.name.toString
Done! |
|
||
@Test def sortedCompletions: Unit = | ||
fromInitialState { implicit state => | ||
val src = """class Foo { def comp1 = 1; def compa = 3; def compA = 4 }""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use simple quotes. Triple quotes are not needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the code snippet I gave you. I think the ordering is clearer:
class Foo { def comp3 = 3; def comp1 = 1; def comp2 = 2 }
val expected = List("comp1", "comp2", "comp3")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @ankitson 🎉
@@ -219,7 +219,7 @@ object Interactive { | |||
case _ => getScopeCompletions(ctx) | |||
} | |||
interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %") | |||
(completionPos, completions.toList) | |||
(completionPos, completions.toList.sortBy(_.name.toString)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smarter We have an ordering for Name
that differs from the default String
ordering. I am wondering if we should use it here? The Name ordering will not group type names and term names together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they should be grouped together, but we should also not display type completions if we're not in a type context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure but that's probably out of the scope of this PR
This seems to be a quick fix for #4390. Its my first PR to dotty so I might be missing something.